package seismosurfer.gui.panel;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.help.CSH;
import javax.swing.BorderFactory;

import seismosurfer.gui.TimeSliderToolBar;
import seismosurfer.util.ClientRegistry;

import com.bbn.openmap.gui.BasicMapPanel;
import com.bbn.openmap.gui.MapPanelChild;
import com.bbn.openmap.gui.OMComponentPanel;
import com.bbn.openmap.gui.ToolPanel;

/**
 * This panel holds the two toolbars: the ToolPanel
 * and the TimeSliderToolBar.
 *
 */
public class ToolBarPanel extends OMComponentPanel implements MapPanelChild {
    
    private static final long serialVersionUID = -5060888609999180230L;

    private ToolPanel tp;

    private TimeSliderToolBar tb;

    public ToolBarPanel() {
        super();
        setLayout(new BorderLayout());
    }

    public void findAndInit(Object obj) {

        if (obj instanceof ToolPanel) {
            tp = (ToolPanel) obj;
            tp.setBorder(BorderFactory.createLineBorder(Color.GRAY));
            add(tp, BorderLayout.NORTH);

            CSH.setHelpIDString(tp, "mainToolbar");

            ClientRegistry.setToolPanel(tp);
        } else if (obj instanceof TimeSliderToolBar) {
            tb = (TimeSliderToolBar) obj;
            tb.setBorder(BorderFactory.createLineBorder(Color.GRAY));
            add(tb, BorderLayout.SOUTH);

            CSH.setHelpIDString(tb, "time");
        }

        if (obj instanceof BasicMapPanel) {
            System.out.println("BasicMapPanel found in ToolBarPanel!!!");
        }

        if (tb != null) {
            tb.findAndInit(obj);
        }

    }

    public void findAndUndo(Object obj) {

        tb.findAndUndo(obj);

        if (obj instanceof ToolPanel) {
            remove(tp);
        } else if (obj instanceof TimeSliderToolBar) {

            remove(tb);
        }

    }

    /**
     * BorderLayout.NORTH by default for this class.
     */
    protected String preferredLocation = java.awt.BorderLayout.NORTH;

    /**
     * MapPanelChild method.
     */
    public void setPreferredLocation(String value) {
        preferredLocation = value;
    }

    /** MapPanelChild method. */
    public String getPreferredLocation() {
        return preferredLocation;
    }

}
